package emulator.unittest.util;

import static org.junit.Assert.*;

import org.junit.Test;

import emulator.hardware.bits.EdgeDetector;


public class EdgeDetectorTest {
	
	@Test
	public void testConstructor()
	{
		assertFalse(new EdgeDetector(false, false).getValue());
		assertFalse(new EdgeDetector(false, true).getValue());
		assertFalse(new EdgeDetector(true, false).getValue());
		assertFalse(new EdgeDetector(true, true).getValue());
	}
	
	@Test
	public void testHighTriggerFromLowStart()
	{
		EdgeDetector detector = new EdgeDetector(true, false);
		detector.setValue(true);
		assertTrue(detector.getValue());
		assertFalse(detector.getValue());
		detector.setValue(true);
		assertFalse(detector.getValue());
		detector.setValue(false);
		assertFalse(detector.getValue());
		detector.setValue(true);
		assertTrue(detector.getValue());
	}
	
	@Test
	public void testLowTriggerFromHighStart()
	{
		EdgeDetector detector = new EdgeDetector(false, true);
		detector.setValue(false);
		assertTrue(detector.getValue());
		assertFalse(detector.getValue());
		detector.setValue(false);
		assertFalse(detector.getValue());
		detector.setValue(true);
		assertFalse(detector.getValue());
		detector.setValue(false);
		assertTrue(detector.getValue());
	}
}
